package cn.wx.system.service.impl;

import cn.wx.basic.service.impl.BaseServiceImpl;
import cn.wx.system.domain.Dictionarydetail;
import cn.wx.system.domain. Dictionarytype;
import cn.wx.system.mapper.DictionarydetailMapper;
import cn.wx.system.mapper.DictionarytypeMapper;
import cn.wx.system.service.IDictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class DictionarytypeServiceImpl extends BaseServiceImpl< Dictionarytype> implements IDictionarytypeService {

    @Autowired
    private  DictionarytypeMapper dictionarytypeMapper;
    @Autowired
    private DictionarydetailMapper dictionarydetailMapper;


    @Transactional
    @Override
    public void remove(Long id) {

        //通过typeid查询所有对象
        List<Dictionarydetail> systemDetails = dictionarydetailMapper.selectByTypeId(id);

        ArrayList<Long> ids = new ArrayList<>();
        for (Dictionarydetail detail : systemDetails) {
            Long id1= detail.getId();
            ids.add(id1);
        }
        dictionarydetailMapper.patchDel(ids);
        dictionarytypeMapper.remove(id);
    }


    @Transactional
    @Override
    public void patchDel(List<Long> ids) {
        for (Long id : ids) {
            List<Dictionarydetail> systemDetails = dictionarydetailMapper.selectByTypeId(id);

            ArrayList<Long> dids = new ArrayList<>();
            for (Dictionarydetail detail : systemDetails) {
                Long did= detail.getId();
                dids.add(did);
            }

            dictionarydetailMapper.patchDel(dids);
        }



        dictionarytypeMapper.patchDel(ids);
    }


    }

